﻿import plugin from '../../lib/plugins/plugin.js'
import common from'../../lib/common/common.js'
import fetch from "node-fetch";
import fs from 'fs'

let cooldowns = new Map();
let cdtime = 300
export class slander extends plugin {
    constructor() {
        super({
            name: '塔罗牌',
            dsc: '塔罗牌',
            /** https://oicqjs.github.io/oicq/#events */
            event: 'message',
            priority: 1000,
            rule: [
                {
                    reg: '^#?(抽)?(取?)塔罗牌$',
                    fnc: 'taluo'
                }
            ]
        })
    }
  

  async taluo(e){
    if (!e.isMaster) {
        let groupId = e.user_id; 
        const cooldown = cooldowns[groupId];
        if (cooldown && cooldown > Date.now()) {
            e.reply(`指令冷却中～`);
            return;
        }
    cooldowns[groupId] = Date.now() + cdtime * 1000;
    }
    let dem = `./resources/Tarot`;
    let wen = `${dem}/data.json`;
    if (!fs.existsSync(dem) || !fs.existsSync(wen)) {
        return
    }
	let data = JSON.parse(fs.readFileSync(wen, 'utf8'))
	let keys = Object.keys(data)
	let randomKey = keys[Math.floor(Math.random() * keys.length)]
    let selectedCard = data[randomKey]
	let replyMsg = [
	        segment.image(`${dem}/${randomKey}.png`),
			`${randomKey}（${selectedCard.name_en}）\n${selectedCard.type}：${selectedCard.meaning}\n解读：${selectedCard.msg}`
            ]
    await e.reply(replyMsg, true);
    return true;
  }

}

